package org.apache.poi.xwpf.usermodel;

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;

public class IlvlTree {
	private IlvlNode root;
	private CTAbstractNum ctan;
	public IlvlTree(CTAbstractNum ctan){
		root=new IlvlNode();
		this.ctan=ctan;
	}
	public int getStartOfIlvl(int ilvl){
		return ctan.getLvlArray()[ilvl].getStart().getVal().intValue();
	}
	public String add(int ilvl){
		int i=0;
		IlvlNode current=root;
		StringBuffer sb=new StringBuffer();
		while(i<ilvl){
			IlvlNode tmp = current.getLastChild();
			if(tmp==null)
				tmp=current.addChild();
			sb.append(current.getChildrenLength()+getStartOfIlvl(i)-1+"_");
			current=tmp;
			i++;
		}
		current.addChild();
		sb.append(current.getChildrenLength()+getStartOfIlvl(i)-1+"_");
		return sb.toString();
	}
}
